<?php
/**
 * 企业小程序模块微站定义
 *
 * @author 悟空源码社区
 * @url http://www.5kym.com/
 */
defined('IN_IA') or exit('Access Denied');

class Weixinmao_zpModuleSite extends WeModuleSite {
  

	public function doWebIntro() {
		//这个操作被定义用来呈现 管理中心导航菜单
		global $_W,$_GPC;
		load()->func('tpl');
        $operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';

	   if ($operation == 'post') {
            $id = intval($_GPC['id']);
            if (checksubmit('submit')) {
                $data = array(
                    'uniacid' => $_W['uniacid'],
					'name'=>$_GPC['name'],
					'address'=>$_GPC['address'],
					'tel'=>$_GPC['tel'],
					'qq'=>$_GPC['qq'],
					'email'=>$_GPC['email'],
					'logo'=>$_GPC['logo'],
					'name'=>$_GPC['name'],
					'opentime'=>$_GPC['opentime'],
					'city'=>$_GPC['city'],
					'lng'=>$_GPC['location']['lng'],
					'lat'=>$_GPC['location']['lat'],
                    'content' => htmlspecialchars_decode($_GPC['content']),
                    'ischeck'=>$_GPC['ischeck'],
                    'iscompany'=>$_GPC['iscompany'],
                    'isnote'=>$_GPC['isnote'],
                      'issms'=>$_GPC['issms'],
                     'smsaccount'=>$_GPC['smsaccount'],
                      'smspwd'=>$_GPC['smspwd'],
                        'notenum'=>$_GPC['notenum'],
                    'createtime' => TIMESTAMP,
                );
               
                if (!empty($id)) {
                    unset($data['createtime']);
                    pdo_update('weixinmao_zp_intro', $data, array('id' => $id));
                } else {
                    pdo_insert('weixinmao_zp_intro', $data);
                    $id = pdo_insertid();
                }
                message('更新成功！', $this->createWebUrl('intro', array('op' => 'display')), 'success');
            }
            if (empty($shop)) {
                $shop['displayorder'] = 0;
                $shop['enabled'] = 1;
            }
        }elseif($operation == 'display'){
   	
		$intro = pdo_fetch("select * from " . tablename('weixinmao_zp_intro') . " where uniacid=:uniacid limit 1", array(":uniacid" => $_W['uniacid']));
		include $this->template('intro');
		}
	}



		public function doWebUserinfo() 

		{
		//这个操作被定义用来呈现 管理中心导航菜单
		global $_GPC, $_W;
		load()->func('tpl');
		$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
		if ($operation == 'post') {
			
	

		
			
		} elseif ($operation == 'display') {
			
			echo $_GPC['keyword'];
			$pindex = max(1, intval($_GPC['page']));
			$psize = 15;
			$condition = " WHERE `uniacid` = :uniacid AND uid>0 AND tel <> '' ";
			$params = array(':uniacid' => $_W['uniacid']);
			
			if (!empty($_GPC['keyword'])) {
				$condition .= ' AND `title` LIKE :title';
				$params[':title'] = '%' . trim($_GPC['keyword']) . '%';
			}
			
			
			$sql = 'SELECT COUNT(*) FROM ' . tablename('weixinmao_zp_userinfo') .$condition ;

			$total = pdo_fetchcolumn($sql, $params);
			
			if (!empty($total)) {
				$sql = 'SELECT * FROM  ' . tablename('weixinmao_zp_userinfo') .$condition.' ORDER BY  `createtime`  DESC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
				$list = pdo_fetchall($sql, $params);
				$pager = pagination($total, $pindex, $psize);
			}
			foreach($list as $k=>$v)
			{
				$list[$k]['avatarUrl'] = tomedia($v['avatarUrl']);
			}
			
			
		} elseif ($operation == 'delete') {
			$id = intval($_GPC['id']);
			$row = pdo_fetch("SELECT id FROM " . tablename('weixinmao_zp_userinfo') . " WHERE id = :id", array(':id' => $id));
			if (empty($row)) {
				message('抱歉，商品不存在或是已经被删除！');
			}

			pdo_delete('weixinmao_zp_userinfo', array('id' => $id));
			message('删除成功！', referer(), 'success');
		}
		include $this->template('userinfo');
		
	}



	public function doWebMsgtpl() {
		global $_W, $_GPC;
			load()->func('tpl');
		$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
		if ($operation == 'display') {
			$list = pdo_fetchall("SELECT * FROM " . tablename('weixinmao_zp_msgtpl') . " WHERE weid = '{$_W['uniacid']}' ");
		} elseif ($operation == 'post') {
			$id = intval($_GPC['id']);
			if (checksubmit('submit')) {
				$data = array(
					'weid' => $_W['uniacid'],
					'msgid' => $_GPC['msgid'],
					'msgcontent' => $_GPC['msgcontent'],
					'msgtype' => $_GPC['msgtype'],
					'enabled' => intval($_GPC['enabled']),
				);
			
				if (!empty($id)) {
					pdo_update('weixinmao_zp_msgtpl', $data, array('id' => $id));
				} else {
					pdo_insert('weixinmao_zp_msgtpl', $data);
					$id = pdo_insertid();
				}
				message('更新成功！', $this->createWebUrl('msgtpl', array('op' => 'display')), 'success');
			}
			$adv = pdo_fetch("select * from " . tablename('weixinmao_zp_msgtpl') . " where id=:id and weid=:weid limit 1", array(":id" => $id, ":weid" => $_W['uniacid']));
		} elseif ($operation == 'delete') {
			$id = intval($_GPC['id']);
			$adv = pdo_fetch("SELECT id FROM " . tablename('weixinmao_zp_msgtpl') . " WHERE id = '$id' AND weid=" . $_W['uniacid'] . "");
			if (empty($adv)) {
				message('抱歉，不存在或是已经被删除！', $this->createWebUrl('msgtpl', array('op' => 'display')), 'error');
			}
			pdo_delete('weixinmao_zp_msgtpl', array('id' => $id));
			message('删除成功！', $this->createWebUrl('msgtpl', array('op' => 'display')), 'success');
		} else {
			message('请求方式不存在');
		}
		include $this->template('msgtpl', TEMPLATE_INCLUDEPATH, true);
	}



public function doWebNav() {
		global $_W, $_GPC;
			load()->func('tpl');
		$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
		if ($operation == 'display') {
			$list = pdo_fetchall("SELECT * FROM " . tablename('weixinmao_zp_nav') . " WHERE weid = '{$_W['uniacid']}' ORDER BY displayorder DESC");
		} elseif ($operation == 'post') {
			$id = intval($_GPC['id']);
			if (checksubmit('submit')) {
				$data = array(
					'weid' => $_W['uniacid'],
					'advname' => $_GPC['advname'],
					'link' => $_GPC['link'],
					'enabled' => intval($_GPC['enabled']),
					'displayorder' => intval($_GPC['displayorder']),
					'thumb'=>$_GPC['thumb']
				);
				if (!empty($id)) {
					pdo_update('weixinmao_zp_nav', $data, array('id' => $id));
				} else {
					pdo_insert('weixinmao_zp_nav', $data);
					$id = pdo_insertid();
				}
				message('更新导航成功！', $this->createWebUrl('nav', array('op' => 'display')), 'success');
			}
			$adv = pdo_fetch("select * from " . tablename('weixinmao_zp_nav') . " where id=:id and weid=:weid limit 1", array(":id" => $id, ":weid" => $_W['uniacid']));
		} elseif ($operation == 'delete') {
			$id = intval($_GPC['id']);
			$adv = pdo_fetch("SELECT id FROM " . tablename('weixinmao_zp_nav') . " WHERE id = '$id' AND weid=" . $_W['uniacid'] . "");
			if (empty($adv)) {
				message('抱歉，导航不存在或是已经被删除！', $this->createWebUrl('nav', array('op' => 'display')), 'error');
			}
			pdo_delete('weixinmao_zp_nav', array('id' => $id));
			message('导航删除成功！', $this->createWebUrl('nav', array('op' => 'display')), 'success');
		} else {
			message('请求方式不存在');
		}
		include $this->template('nav', TEMPLATE_INCLUDEPATH, true);
	}

	public function doWebAdv() {
		global $_W, $_GPC;
			load()->func('tpl');
		$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
		if ($operation == 'display') {
			$list = pdo_fetchall("SELECT * FROM " . tablename('weixinmao_zp_adv') . " WHERE weid = '{$_W['uniacid']}' ORDER BY displayorder DESC");
		} elseif ($operation == 'post') {
			$id = intval($_GPC['id']);
			if (checksubmit('submit')) {
				$data = array(
					'weid' => $_W['uniacid'],
					'advname' => $_GPC['advname'],
					'link' => $_GPC['link'],
					'enabled' => intval($_GPC['enabled']),
					'displayorder' => intval($_GPC['displayorder']),
					'thumb'=>$_GPC['thumb'],
					'toway'=>$_GPC['toway'],
					'appid'=>$_GPC['appid']
				);
				if (!empty($id)) {
					pdo_update('weixinmao_zp_adv', $data, array('id' => $id));
				} else {
					pdo_insert('weixinmao_zp_adv', $data);
					$id = pdo_insertid();
				}
				message('更新幻灯片成功！', $this->createWebUrl('adv', array('op' => 'display')), 'success');
			}
			$adv = pdo_fetch("select * from " . tablename('weixinmao_zp_adv') . " where id=:id and weid=:weid limit 1", array(":id" => $id, ":weid" => $_W['uniacid']));
		} elseif ($operation == 'delete') {
			$id = intval($_GPC['id']);
			$adv = pdo_fetch("SELECT id FROM " . tablename('weixinmao_zp_adv') . " WHERE id = '$id' AND weid=" . $_W['uniacid'] . "");
			if (empty($adv)) {
				message('抱歉，幻灯片不存在或是已经被删除！', $this->createWebUrl('adv', array('op' => 'display')), 'error');
			}
			pdo_delete('weixinmao_zp_adv', array('id' => $id));
			message('幻灯片删除成功！', $this->createWebUrl('adv', array('op' => 'display')), 'success');
		} else {
			message('请求方式不存在');
		}
		include $this->template('adv', TEMPLATE_INCLUDEPATH, true);
	}




	
	public function doWebAgent() {
		global $_W, $_GPC;
			load()->func('tpl');
		$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
		//$sql = 'SELECT * FROM ' . tablename('weixinmao_house_city') . ' WHERE `uniacid` = :uniacid ORDER BY `sort` DESC';
		//$citylist = pdo_fetchall($sql, array(':uniacid' => $_W['uniacid']));
		if ($operation == 'display') {
			
			
				$pindex = max(1, intval($_GPC['page']));
			$psize = 15;
			$condition = ' WHERE `uniacid` = :uniacid ';
			$params = array(':uniacid' => $_W['uniacid']);
			
			if (!empty($_GPC['keyword'])) {
				$condition .= ' AND `title` LIKE :title';
				$params[':title'] = '%' . trim($_GPC['keyword']) . '%';
			}
		
			
			$sql = 'SELECT COUNT(*) FROM ' . tablename('weixinmao_zp_agent') .$condition ;
		
			
			$total = pdo_fetchcolumn($sql, $params);

			$today = strtotime(date('Y-m-d'));
			
			if (!empty($total)) {
				$sql = 'SELECT * FROM  ' . tablename('weixinmao_zp_agent') .$condition.' ORDER BY  `createtime`  DESC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
				$list = pdo_fetchall($sql, $params);
			
				$pager = pagination($total, $pindex, $psize);
			}
			
			
			
			
			
		} elseif ($operation == 'post') {
			$id = intval($_GPC['id']);
		
			if (checksubmit('submit')) {
				$data = array(
					'uniacid' => $_W['uniacid'],
					'name' => $_GPC['name'],
					'tel'=>$_GPC['tel'],
					'weixin' => $_GPC['weixin'],
					'email' => $_GPC['email'],
					'status'=> $_GPC['status'],
					'createtime' => TIMESTAMP
					);
				if (!empty($id)) {
					pdo_update('weixinmao_zp_agent', $data, array('id' => $id));
				} else {
					pdo_insert('weixinmao_zp_agent', $data);
					$id = pdo_insertid();
				}
				message('更新成功！', $this->createWebUrl('agent', array('op' => 'display')), 'success');
			}

			$agent = pdo_fetch("select * from " . tablename('weixinmao_zp_agent') . " where id=:id and uniacid=:uniacid limit 1", array(":id" => $id, ":uniacid" => $_W['uniacid']));
		} elseif ($operation == 'delete') {
			$id = intval($_GPC['id']);
			$oldhouseprice = pdo_fetch("SELECT id FROM " . tablename('weixinmao_zp_agent') . " WHERE id = '$id' AND uniacid=" . $_W['uniacid'] . "");
			if (empty($oldhouseprice)) {
				message('抱歉，不存在或是已经被删除！', $this->createWebUrl('agent', array('op' => 'display')), 'error');
			}
			pdo_delete('weixinmao_zp_agent', array('id' => $id));
			message('删除成功！', $this->createWebUrl('agent', array('op' => 'display')), 'success');
		} else {
			message('请求方式不存在');
		}
		include $this->template('agent', TEMPLATE_INCLUDEPATH, true);
	}
	




public function doWebContent() {
		//这个操作被定义用来呈现 管理中心导航菜单
				global $_GPC, $_W;
		load()->func('tpl');

		$sql = 'SELECT * FROM ' . tablename('weixinmao_zp_category') . ' WHERE `weid` = :weid ORDER BY `parentid`, `displayorder` DESC';
		
		$category = pdo_fetchall($sql, array(':weid' => $_W['uniacid']), 'id');
		
	
		$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
		if ($operation == 'post') {
			
			$id = $_GPC['id'];
	
			 if (!empty($id)) {
				 
				 		$item = pdo_fetch("SELECT *  FROM " . tablename('weixinmao_zp_content') . " WHERE id = :id", array(':id' => $id));
					
						
			}
			
			$pid = $_GPC['category']['parentid'];
			
			$sid = 0;

			
			if (checksubmit('submit')) {
				//print_r($_GPC);
				//exit;
                $data = array(
                    'uniacid' => $_W['uniacid'],
					'title'=>$_GPC['title'],
					'pid'=>$pid,
					'sid'=>$sid,
                    'content' => ihtmlspecialchars($_GPC['content']),
					'sort'=>$_GPC['sort'],
					'thumb'=>$_GPC['thumb'],
                    'createtime' => TIMESTAMP,
                );
               
                if (!empty($id)) {
                    unset($data['createtime']);
                    pdo_update('weixinmao_zp_content', $data, array('id' => $id));
                } else {
                    pdo_insert('weixinmao_zp_content', $data);
                    $id = pdo_insertid();
                }
                message('更新成功！', $this->createWebUrl('content', array('op' => 'display')), 'success');
            }
			
			
			
			
		} elseif ($operation == 'display') {
			
			echo $_GPC['keyword'];
			$pindex = max(1, intval($_GPC['page']));
			$psize = 15;
			$condition = ' WHERE `uniacid` = :uniacid ';
			$params = array(':uniacid' => $_W['uniacid']);
			
			if (!empty($_GPC['keyword'])) {
				$condition .= ' AND `title` LIKE :title';
				$params[':title'] = '%' . trim($_GPC['keyword']) . '%';
			}
			
			
			$sql = 'SELECT COUNT(*) FROM ' . tablename('weixinmao_zp_content') .$condition ;

			$total = pdo_fetchcolumn($sql, $params);
			
			if (!empty($total)) {
				$sql = 'SELECT * FROM  ' . tablename('weixinmao_zp_content') .$condition.' ORDER BY  `sort`  DESC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
				$list = pdo_fetchall($sql, $params);
				$pager = pagination($total, $pindex, $psize);
			}
			if($list)
			{
					foreach($list as $k=>$v)
					{
						$parent_info = pdo_fetch("SELECT name  FROM " . tablename('weixinmao_zp_category') . " WHERE id = :id", array(':id' => $v['pid']));
						$children_info = pdo_fetch("SELECT name  FROM " . tablename('weixinmao_zp_category') . " WHERE id = :id", array(':id' => $v['sid']));

						$list[$k]['parent_catename'] = $parent_info['name'];
						$list[$k]['children_catename'] = $children_info['name'];
					}
			}
			
			
		} elseif ($operation == 'delete') {
			$id = intval($_GPC['id']);
			$row = pdo_fetch("SELECT id FROM " . tablename('weixinmao_zp_content') . " WHERE id = :id", array(':id' => $id));
			if (empty($row)) {
				message('抱歉，商品不存在或是已经被删除！');
			}

			pdo_delete('weixinmao_zp_content', array('id' => $id));
			message('删除成功！', referer(), 'success');
		}
		include $this->template('goods');
		
	}
	

	public function doWebCompany() {
		//这个操作被定义用来呈现 管理中心导航菜单
		global $_GPC, $_W;
		load()->func('tpl');
		
		$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
			$sql = 'SELECT * FROM ' . tablename('weixinmao_zp_city') . ' WHERE `uniacid` = :uniacid ORDER BY `sort` DESC';
		$citylist = pdo_fetchall($sql, array(':uniacid' => $_W['uniacid']));

	


		if ($operation == 'post') {
			
			$id = $_GPC['id'];


		
	
			 if (!empty($id)) {
				 		$item = pdo_fetch("SELECT *  FROM " . tablename('weixinmao_zp_company') . " WHERE id = :id", array(':id' => $id));

						 $sql = 'SELECT * FROM ' . tablename('weixinmao_zp_area') . ' WHERE `uniacid` = :uniacid AND `cityid`=:cityid ORDER BY `sort` DESC';
						$arealist = pdo_fetchall($sql, array(':uniacid' => $_W['uniacid'],':cityid'=>$item['cityid']));
							
			}
			
		
			if (checksubmit('submit')) {
			
                $data = array(
                    'uniacid' => $_W['uniacid'],
					'companyname'=>$_GPC['companyname'],
					'companycate'=>$_GPC['companycate'],
					'companytype'=>$_GPC['companytype'],
					'companyworker'=>$_GPC['companyworker'],
					'mastername'=>$_GPC['mastername'],
					'tel'=>$_GPC['tel'],
					'cityid'=>$_GPC['cityid'],
					'areaid'=>$_GPC['areaid'],
					'address'=>$_GPC['address'],
					'lng'=>$_GPC['location']['lng'],
					'lat'=>$_GPC['location']['lat'],
                    'content' => htmlspecialchars_decode($_GPC['content']),
					'sort'=>$_GPC['sort'],
					'thumb'=>$_GPC['thumb'],
					'status'=>$_GPC['status'],
					'isrecommand'=>$_GPC['isrecommand'],
					'notenum'=>$_GPC['notenum'],
					//'roleid'=>$_GPC['roleid'],
                   'createtime' => TIMESTAMP,
                );
         
                if (!empty($id)) {
                    unset($data['createtime']);
                    pdo_update('weixinmao_zp_company', $data, array('id' => $id));
                } else {
                				$intro = pdo_get('weixinmao_zp_intro',array('uniacid'=>$_W['uniacid']));

                	$data['notenum'] = $intro['notenum'];
                    pdo_insert('weixinmao_zp_company', $data);
                    $id = pdo_insertid();
                }
                message('更新成功！', $this->createWebUrl('company', array('op' => 'display')), 'success');
            }
			
			
			
			
		}elseif ($operation == 'getcity') {
			$cityid = $_GPC['cityid'];
          $condition = ' WHERE `uniacid` = :uniacid AND `cityid`=:cityid ';
      		  $params = array(':uniacid' => $_W['uniacid'],':cityid'=>$cityid);
			
			
			
			$sql = 'SELECT id,name FROM ' . tablename('weixinmao_zp_area') .$condition ;
        
          $list = pdo_fetchall($sql, $params);
          
          echo json_encode(array('data'=>$list));
          
          exit;
			
		}  elseif ($operation == 'display') {
			
			//echo $_GPC['keyword'];
			$pindex = max(1, intval($_GPC['page']));
			$psize = 15;
			$condition = ' WHERE `uniacid` = :uniacid ';

			$condition = ' WHERE `uniacid` = :uniacid ';
			$params = array(':uniacid' => $_W['uniacid']);
			
			if (!empty($_GPC['keyword'])) {
				$condition .= ' AND `companyname` LIKE :title';
				$params[':title'] = '%' . trim($_GPC['keyword']) . '%';
			}
			
			
			
			$sql = 'SELECT COUNT(*) FROM ' . tablename('weixinmao_zp_company') .$condition ;
		
			$total = pdo_fetchcolumn($sql, $params);
			
			if (!empty($total)) {
				$sql = 'SELECT * FROM  ' . tablename('weixinmao_zp_company') .$condition.' ORDER BY  `createtime`  DESC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
				$list = pdo_fetchall($sql, $params);

				if($list)
				{
					foreach($list as $k=>$v)
						{
							$city_info = pdo_get('weixinmao_zp_city',array('id'=>$v['cityid']));
						$area_info = pdo_get('weixinmao_zp_area',array('id'=>$v['areaid']));
						$companyrole = pdo_get('weixinmao_zp_companyrole',array('id'=>$v['roleid']));
						$list[$k]['cityname'] =  $city_info['name'];
						$list[$k]['areaname'] =  $area_info['name'];
						$list[$k]['rolename'] = $companyrole['title'];
						}
				}
				
				$pager = pagination($total, $pindex, $psize);
			}

			
			
		} elseif ($operation == 'delete') {
			$id = intval($_GPC['id']);
			$row = pdo_fetch("SELECT id FROM " . tablename('weixinmao_zp_company') . " WHERE id = :id", array(':id' => $id));
			if (empty($row)) {
				message('抱歉，企业信息不存在或是已经被删除！');
			}

			pdo_delete('weixinmao_zp_company', array('id' => $id));

			message('删除成功！', referer(), 'success');
		}elseif($operation == 'companyrole'){

			$companyid = $_GPC['id'];

		

			$companyinfo = pdo_get('weixinmao_zp_company',array('id'=>$companyid,'uniacid'=>$_W['uniacid']));

			$companyrole = pdo_get('weixinmao_zp_companyrole',array('id'=>$companyinfo['roleid'],'uniacid'=>$_W['uniacid']));

			if($companyinfo['endtime']>time())
					{

						$condition = ' AND sort > '.$companyrole['sort'];
					}else{

						$condition = ' ';
					}

			$sql = 'SELECT *  FROM ' . tablename('weixinmao_zp_companyrole') . ' WHERE `uniacid` = :uniacid AND isinit = 0 '.$condition.' ORDER BY `sort` ASC';

		    $moneylist = pdo_fetchall($sql, array(':uniacid' => $_W['uniacid']));






		    if (checksubmit('submit')) {

		    			$companyid = $_GPC['id'];
		    			$roleid = $_GPC['roleid'];
                        $companyrole = pdo_get('weixinmao_zp_companyrole',array('uniacid'=>$_W['uniacid'],'id'=>$roleid));

                        $companyinfo = pdo_get('weixinmao_zp_company',array('uniacid'=>$_W['uniacid'],'id'=>$companyid));
                        $jobnum = $companyrole['jobnum'] + $companyinfo['jobnum'];
                        $notenum = $companyrole['notenum'] + $companyinfo['notenum'];

                        $time = 60*60*24*$companyrole['days'];

                       if($companyinfo['endtime']>time())
                       		{
                       				$endtime = $companyinfo['endtime'] + $time;
                        	}else{

                       				//$endtime = 60*60*24*365 + $time;
                       				$endtime = time() + $time ;

                        	}

                       

		                if (!empty($companyid)) {
		                    pdo_update('weixinmao_zp_company',array('jobnum'=>$jobnum,'notenum'=>$notenum,'endtime'=>$endtime,'roleid'=>$roleid), array('id'=>$companyid));
		                } 
                message('更新成功！', $this->createWebUrl('company', array('op' => 'display')), 'success');
            }
		   



		}
	
		include $this->template('company');
		
	}
	


   public function doWebJoblist() {
		//这个操作被定义用来呈现 管理中心导航菜单
		global $_GPC, $_W;
		load()->func('tpl');
		$sql = 'SELECT * FROM ' . tablename('weixinmao_zp_area') . ' WHERE `uniacid` = :uniacid ORDER BY  `sort` DESC';
		
		$arealist = pdo_fetchall($sql, array(':uniacid' => $_W['uniacid']));
		
		$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
		$sql = 'SELECT * FROM ' . tablename('weixinmao_zp_company') . ' WHERE `uniacid` = :uniacid AND endtime > '.time().' ORDER BY `sort` DESC';
		
		$companylist  = pdo_fetchall($sql, array(':uniacid' => $_W['uniacid']));

		$sql = 'SELECT * FROM ' . tablename('weixinmao_zp_jobcate') . ' WHERE `uniacid` = :uniacid ORDER BY `sort` DESC';
		
		$worktypelist  = pdo_fetchall($sql, array(':uniacid' => $_W['uniacid']));


		if ($operation == 'post') {
			
			$id = $_GPC['id'];
	
			 if (!empty($id)) {
				 
				 		$item = pdo_fetch("SELECT *  FROM " . tablename('weixinmao_zp_job') . " WHERE id = :id", array(':id' => $id));

				 	    $item['special'] = explode(',',$item['special']);
							
			}
			
		
			if (checksubmit('submit')) {
						
                $data = array(
                    'uniacid' => $_W['uniacid'],
					'jobtitle'=>$_GPC['jobtitle'],
					'dmoney'=>$_GPC['dmoney'],
					'worktype'=>$_GPC['worktype'],
					'education'=>$_GPC['education'],
					'express'=>$_GPC['express'],
					'jobtype'=>$_GPC['jobtype'],
					'money'=>$_GPC['money'],
					'age'=>$_GPC['age'],
					'num'=>$_GPC['num'],
					'companyid'=>$_GPC['companyid'],
					'sex'=>$_GPC['sex'],
					'special'=>implode(',',$_GPC['special']),
                    'content' => htmlspecialchars_decode($_GPC['content']),
					'sort'=>$_GPC['sort'],
					'isrecommand'=>$_GPC['isrecommand'],
                   'createtime' => TIMESTAMP,
                );
         
                if (!empty($id)) {
                    unset($data['createtime']);
                    pdo_update('weixinmao_zp_job', $data, array('id' => $id));
                } else {

                   $companyinfo = pdo_get('weixinmao_zp_company',array('id'=>$_GPC['companyid'],'uniacid'=>$_W['uniacid']));
					
					$data['endtime'] = $companyinfo['endtime'];


                    pdo_insert('weixinmao_zp_job', $data);
                    $id = pdo_insertid();
                }
                message('更新成功！', $this->createWebUrl('joblist', array('op' => 'display')), 'success');
            }
			
			
			
			
		} elseif ($operation == 'display') {
			
			//echo $_GPC['keyword'];
			$pindex = max(1, intval($_GPC['page']));
			$psize = 15;
			$condition = ' WHERE `uniacid` = :uniacid ';
			$params = array(':uniacid' => $_W['uniacid']);
			
			if (!empty($_GPC['keyword'])) {
				$condition .= ' AND `jobtitle` LIKE :title';
				$params[':title'] = '%' . trim($_GPC['keyword']) . '%';
			}
			
			$sql = 'SELECT COUNT(*) FROM ' . tablename('weixinmao_zp_job') .$condition ;
		
			$total = pdo_fetchcolumn($sql, $params);
			
			if (!empty($total)) {
				$sql = 'SELECT * FROM  ' . tablename('weixinmao_zp_job') .$condition.' ORDER BY  `createtime` DESC ,  `sort`  DESC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
				$list = pdo_fetchall($sql, $params);

				foreach($list as $k=>$v)
			{
				$companyinfo = pdo_fetch("SELECT companyname  FROM " . tablename('weixinmao_zp_company') . " WHERE id = :id AND  `uniacid` = :uniacid", array(':id' => $v['companyid'],':uniacid' => $_W['uniacid']));

				$jobcateinfo = pdo_fetch("SELECT name  FROM " . tablename('weixinmao_zp_jobcate') . " WHERE id = :id  AND  `uniacid` = :uniacid", array(':id' => $v['worktype'],':uniacid' => $_W['uniacid']));

				$list[$k]['companyname'] = $companyinfo['companyname'];

				$list[$k]['jobcatename'] = $jobcateinfo['name'];
			}
			
				
				$pager = pagination($total, $pindex, $psize);
			}

			
			
		} elseif ($operation == 'delete') {
			$id = intval($_GPC['id']);
			$row = pdo_fetch("SELECT id FROM " . tablename('weixinmao_zp_job') . " WHERE id = :id", array(':id' => $id));
			if (empty($row)) {
				message('抱歉，职位信息不存在或是已经被删除！');
			}

			pdo_delete('weixinmao_zp_job', array('id' => $id));

			message('删除成功！', referer(), 'success');
		}
	
		include $this->template('joblist');
		
	}
	






   public function doWebNotelist() {
		//这个操作被定义用来呈现 管理中心导航菜单
		global $_GPC, $_W;
		load()->func('tpl');
		
		$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
		$sql = 'SELECT * FROM ' . tablename('weixinmao_zp_company') . ' WHERE `uniacid` = :uniacid ORDER BY `sort` DESC';
		
		$companylist  = pdo_fetchall($sql, array(':uniacid' => $_W['uniacid']));

		$sql = 'SELECT * FROM ' . tablename('weixinmao_zp_jobcate') . ' WHERE `uniacid` = :uniacid ORDER BY `sort` DESC';
		
		$worktypelist  = pdo_fetchall($sql, array(':uniacid' => $_W['uniacid']));


		if ($operation == 'post') {
			
			$id = $_GPC['id'];
	
			 if (!empty($id)) {
				 
				 		$item = pdo_fetch("SELECT *  FROM " . tablename('weixinmao_zp_jobnote') . " WHERE id = :id", array(':id' => $id));
							
			}
			
		
			if (checksubmit('submit')) {
			
                $data = array(
                    'uniacid' => $_W['uniacid'],
					'jobtitle'=>$_GPC['jobtitle'],
					'worktype'=>$_GPC['worktype'],
					'money'=>$_GPC['money'],
					'age'=>$_GPC['age'],
					'num'=>$_GPC['num'],
					'companyid'=>$_GPC['companyid'],
					'sex'=>$_GPC['sex'],
					'special'=>implode(',',$_GPC['special']),
                    'content' => htmlspecialchars_decode($_GPC['content']),
					'sort'=>$_GPC['sort'],
					'isrecommand'=>$_GPC['isrecommand'],
                   'createtime' => TIMESTAMP,
                );
         
                if (!empty($id)) {
                    unset($data['createtime']);
                    pdo_update('weixinmao_zp_job', $data, array('id' => $id));
                } else {
                    pdo_insert('weixinmao_zp_job', $data);
                    $id = pdo_insertid();
                }
                message('更新成功！', $this->createWebUrl('joblist', array('op' => 'display')), 'success');
            }
			
			
			
			
		} elseif ($operation == 'display') {
			
			//echo $_GPC['keyword'];
			$pindex = max(1, intval($_GPC['page']));
			$psize = 15;
			$condition = ' WHERE `uniacid` = :uniacid ';
			$params = array(':uniacid' => $_W['uniacid']);
			
			if (!empty($_GPC['keyword'])) {
				$condition .= ' AND `name` LIKE :title';
				$params[':title'] = '%' . trim($_GPC['keyword']) . '%';
			}
			
			
			$sql = 'SELECT COUNT(*) FROM ' . tablename('weixinmao_zp_jobnote') .$condition ;
		
			$total = pdo_fetchcolumn($sql, $params);
			
			if (!empty($total)) {
				$sql = 'SELECT * FROM  ' . tablename('weixinmao_zp_jobnote') .$condition.' ORDER BY  `createtime`  DESC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
				$list = pdo_fetchall($sql, $params);
				
				$pager = pagination($total, $pindex, $psize);
			}
           	if($list)
			{
				
				
				foreach($list as $k=>$v)
					{
						$city_info = pdo_get('weixinmao_zp_city',array('id'=>$v['cityid']));

						$list[$k]['cityname'] =  $city_info['name'];
					}
				
				
			}
			
			
		} elseif ($operation == 'delete') {
			$id = intval($_GPC['id']);
			$row = pdo_fetch("SELECT id FROM " . tablename('weixinmao_zp_jobnote') . " WHERE id = :id", array(':id' => $id));
			if (empty($row)) {
				message('抱歉，职位信息不存在或是已经被删除！');
			}

			pdo_delete('weixinmao_zp_jobnote', array('id' => $id));

			message('删除成功！', referer(), 'success');
		}
	
		include $this->template('notelist');
		
	}




public function doWebRegsub() {
		global $_W, $_GPC;
			load()->func('tpl');

		$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
		if ($operation == 'display') {
$pindex = max(1, intval($_GPC['page']));
			$psize = 15;
			$condition = ' WHERE `uniacid` = :uniacid ';
			$params = array(':uniacid' => $_W['uniacid']);
			
			if (!empty($_GPC['keyword'])) {
				$condition .= ' AND `name` LIKE :title';
				$params[':title'] = '%' . trim($_GPC['keyword']) . '%';
			}
			

			$sql = 'SELECT COUNT(*) FROM ' . tablename('weixinmao_zp_regsub') .$condition ;

			$total = pdo_fetchcolumn($sql, $params);
			
			if (!empty($total)) {
				$sql = 'SELECT * FROM  ' . tablename('weixinmao_zp_regsub') .$condition.' ORDER BY  `createtime`  DESC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
				$list = pdo_fetchall($sql, $params);
				$pager = pagination($total, $pindex, $psize);
			}




//			$list = pdo_fetchall("SELECT * FROM " . tablename('weixinmao_zp_city') . " WHERE uniacid = '{$_W['uniacid']}' ORDER BY sort DESC");


		} elseif ($operation == 'post') {
			
		} elseif ($operation == 'delete') {
			$id = intval($_GPC['id']);
			$area = pdo_fetch("SELECT id FROM " . tablename('weixinmao_zp_regsub') . " WHERE id = '$id' AND uniacid=" . $_W['uniacid'] . "");
			if (empty($area)) {
				message('抱歉，不存在或是已经被删除！', $this->createWebUrl('regsub', array('op' => 'display')), 'error');
			}
			pdo_delete('weixinmao_zp_regsub', array('id' => $id));
			message('删除成功！', $this->createWebUrl('regsub', array('op' => 'display')), 'success');
		}  else {
			message('请求方式不存在');
		}
		include $this->template('regsub', TEMPLATE_INCLUDEPATH, true);
	}


public function doWebRegmoney() {
		global $_W, $_GPC;
			load()->func('tpl');

		$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
		if ($operation == 'display') {
$pindex = max(1, intval($_GPC['page']));
			$psize = 15;
			$condition = ' WHERE `uniacid` = :uniacid ';
			$params = array(':uniacid' => $_W['uniacid']);
			
			if (!empty($_GPC['keyword'])) {
				$condition .= ' AND `name` LIKE :title';
				$params[':title'] = '%' . trim($_GPC['keyword']) . '%';
			}
			

			$sql = 'SELECT COUNT(*) FROM ' . tablename('weixinmao_zp_regmoney') .$condition ;

			$total = pdo_fetchcolumn($sql, $params);
			
			if (!empty($total)) {
				$sql = 'SELECT * FROM  ' . tablename('weixinmao_zp_regmoney') .$condition.' ORDER BY  `createtime`  DESC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
				$list = pdo_fetchall($sql, $params);
				$pager = pagination($total, $pindex, $psize);
			}




//			$list = pdo_fetchall("SELECT * FROM " . tablename('weixinmao_zp_city') . " WHERE uniacid = '{$_W['uniacid']}' ORDER BY sort DESC");


		} elseif ($operation == 'post') {
			
		} elseif ($operation == 'delete') {
			$id = intval($_GPC['id']);
			$area = pdo_fetch("SELECT id FROM " . tablename('weixinmao_zp_regmoney') . " WHERE id = '$id' AND uniacid=" . $_W['uniacid'] . "");
			if (empty($area)) {
				message('抱歉，不存在或是已经被删除！', $this->createWebUrl('regmoney', array('op' => 'display')), 'error');
			}
			pdo_delete('weixinmao_zp_regmoney', array('id' => $id));
			message('删除成功！', $this->createWebUrl('regmoney', array('op' => 'display')), 'success');
		}  else {
			message('请求方式不存在');
		}
		include $this->template('regmoney', TEMPLATE_INCLUDEPATH, true);
	}


public function doWebCity() {
		global $_W, $_GPC;
			load()->func('tpl');

		$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
		if ($operation == 'display') {
$pindex = max(1, intval($_GPC['page']));
			$psize = 15;
			$condition = ' WHERE `uniacid` = :uniacid ';
			$params = array(':uniacid' => $_W['uniacid']);
			
			if (!empty($_GPC['keyword'])) {
				$condition .= ' AND `name` LIKE :title';
				$params[':title'] = '%' . trim($_GPC['keyword']) . '%';
			}
			

			$sql = 'SELECT COUNT(*) FROM ' . tablename('weixinmao_zp_city') .$condition ;

			$total = pdo_fetchcolumn($sql, $params);
			
			if (!empty($total)) {
				$sql = 'SELECT * FROM  ' . tablename('weixinmao_zp_city') .$condition.' ORDER BY  `sort`  DESC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
				$list = pdo_fetchall($sql, $params);
				$pager = pagination($total, $pindex, $psize);
			}




//			$list = pdo_fetchall("SELECT * FROM " . tablename('weixinmao_zp_city') . " WHERE uniacid = '{$_W['uniacid']}' ORDER BY sort DESC");


		} elseif ($operation == 'post') {
			$id = intval($_GPC['id']);
			if (checksubmit('submit')) {
				$data = array(
					'uniacid' => $_W['uniacid'],
					'name' => $_GPC['name'],
					'firstname' => $_GPC['firstname'],
					'sort' => $_GPC['displayorder'],
					'enabled'=>1,
					'ison'=>$_GPC['ison'],
					'ishot'=>$_GPC['ishot'],
					);
				if (!empty($id)) {
					pdo_update('weixinmao_zp_city', $data, array('id' => $id));


				} else {
					pdo_insert('weixinmao_zp_city', $data);
					$id = pdo_insertid();
				}
				message('更新成功！', $this->createWebUrl('city', array('op' => 'display')), 'success');
			}
			$area = pdo_fetch("select * from " . tablename('weixinmao_zp_city') . " where id=:id and uniacid=:uniacid limit 1", array(":id" => $id, ":uniacid" => $_W['uniacid']));
		} elseif ($operation == 'delete') {
			$id = intval($_GPC['id']);
			$area = pdo_fetch("SELECT id FROM " . tablename('weixinmao_zp_city') . " WHERE id = '$id' AND uniacid=" . $_W['uniacid'] . "");
			if (empty($area)) {
				message('抱歉，不存在或是已经被删除！', $this->createWebUrl('city', array('op' => 'display')), 'error');
			}
			pdo_delete('weixinmao_zp_city', array('id' => $id));
			message('删除成功！', $this->createWebUrl('city', array('op' => 'display')), 'success');
		} elseif ($operation == 'donedate') {
				$cityinfo = pdo_get('weixinmao_zp_city',array("uniacid" => $_W['uniacid'],'ison'=>1));
				pdo_update('weixinmao_zp_area',array('cityid'=>$cityinfo['id']),array('uniacid' => $_W['uniacid']));
				pdo_update('weixinmao_zp_company',array('cityid'=>$cityinfo['id']),array('uniacid' => $_W['uniacid']));
				pdo_update('weixinmao_zp_jobnote',array('cityid'=>$cityinfo['id']),array('uniacid' => $_W['uniacid']));

			


				message('操作完成', $this->createWebUrl('city', array('op' => 'display')), 'success');



		} else {
			message('请求方式不存在');
		}
		include $this->template('city', TEMPLATE_INCLUDEPATH, true);
	}
	





public function doWebArea() {
		global $_W, $_GPC;
			load()->func('tpl');
		$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
				$citylist = pdo_fetchall("select id, name from " . tablename('weixinmao_zp_city') . " where  uniacid=:uniacid ", array( ":uniacid" => $_W['uniacid']));

		if ($operation == 'display') {


			$pindex = max(1, intval($_GPC['page']));
			$psize = 15;
			$condition = ' WHERE `uniacid` = :uniacid ';
			$params = array(':uniacid' => $_W['uniacid']);
			
			if (!empty($_GPC['keyword'])) {
				$condition .= ' AND `name` LIKE :title';
				$params[':title'] = '%' . trim($_GPC['keyword']) . '%';
			}
			

			$sql = 'SELECT COUNT(*) FROM ' . tablename('weixinmao_zp_area') .$condition ;

			$total = pdo_fetchcolumn($sql, $params);
			
			if (!empty($total)) {
				$sql = 'SELECT * FROM  ' . tablename('weixinmao_zp_area') .$condition.' ORDER BY  `sort`  DESC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
				$list = pdo_fetchall($sql, $params);
				$pager = pagination($total, $pindex, $psize);
			}



		} elseif ($operation == 'post') {
			$id = intval($_GPC['id']);
			if (checksubmit('submit')) {
				$data = array(
					'uniacid' => $_W['uniacid'],
					'name' => $_GPC['name'],
					'cityid' => $_GPC['cityid'],
					'sort' => $_GPC['sort'],
					'enabled'=>$_GPC['enabled']
					);
					
				if (!empty($id)) {
					pdo_update('weixinmao_zp_area', $data, array('id' => $id));
				} else {
					pdo_insert('weixinmao_zp_area', $data);
					$id = pdo_insertid();
				}
				message('更新区域成功！', $this->createWebUrl('area', array('op' => 'display')), 'success');
			}
			$area = pdo_fetch("select * from " . tablename('weixinmao_zp_area') . " where id=:id and uniacid=:uniacid limit 1", array(":id" => $id, ":uniacid" => $_W['uniacid']));
		} elseif ($operation == 'delete') {
			$id = intval($_GPC['id']);
			$area = pdo_fetch("SELECT id FROM " . tablename('weixinmao_zp_area') . " WHERE id = '$id' AND uniacid=" . $_W['uniacid'] . "");
			if (empty($area)) {
				message('抱歉，不存在或是已经被删除！', $this->createWebUrl('area', array('op' => 'display')), 'error');
			}
			pdo_delete('weixinmao_zp_area', array('id' => $id));
			message('删除成功！', $this->createWebUrl('area', array('op' => 'display')), 'success');
		} else {
			message('请求方式不存在');
		}
		include $this->template('area', TEMPLATE_INCLUDEPATH, true);
	}

public function doWebJobcate() {
		global $_W, $_GPC;
			load()->func('tpl');
		$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
		if ($operation == 'display') {
			$list = pdo_fetchall("SELECT * FROM " . tablename('weixinmao_zp_jobcate') . " WHERE uniacid = '{$_W['uniacid']}' ORDER BY sort DESC");
		} elseif ($operation == 'post') {
			$id = intval($_GPC['id']);
			if (checksubmit('submit')) {
				$data = array(
					'uniacid' => $_W['uniacid'],
					'name' => $_GPC['name'],
					'sort' => $_GPC['sort'],
					'enabled'=>$_GPC['enabled']
					);
					
				if (!empty($id)) {
					pdo_update('weixinmao_zp_jobcate', $data, array('id' => $id));
				} else {
					pdo_insert('weixinmao_zp_jobcate', $data);
					$id = pdo_insertid();
				}
				message('更新职业类别成功！', $this->createWebUrl('jobcate', array('op' => 'display')), 'success');
			}
			$area = pdo_fetch("select * from " . tablename('weixinmao_zp_jobcate') . " where id=:id and uniacid=:uniacid limit 1", array(":id" => $id, ":uniacid" => $_W['uniacid']));
		} elseif ($operation == 'delete') {
			$id = intval($_GPC['id']);
			$area = pdo_fetch("SELECT id FROM " . tablename('weixinmao_zp_jobcate') . " WHERE id = '$id' AND uniacid=" . $_W['uniacid'] . "");
			if (empty($area)) {
				message('抱歉，不存在或是已经被删除！', $this->createWebUrl('jobcate', array('op' => 'display')), 'error');
			}
			pdo_delete('weixinmao_zp_jobcate', array('id' => $id));
			message('删除成功！', $this->createWebUrl('jobcate', array('op' => 'display')), 'success');
		} else {
			message('请求方式不存在');
		}
		include $this->template('jobcate', TEMPLATE_INCLUDEPATH, true);
	}





	public function doWebjobprice() {
		global $_W, $_GPC;
			load()->func('tpl');
		$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
		if ($operation == 'display') {
			$list = pdo_fetchall("SELECT * FROM " . tablename('weixinmao_zp_jobprice') . " WHERE uniacid = '{$_W['uniacid']}' ORDER BY sort DESC");
		} elseif ($operation == 'post') {
			$id = intval($_GPC['id']);
		
			if (checksubmit('submit')) {
				$data = array(
					'uniacid' => $_W['uniacid'],
					'name' => $_GPC['name'],
				    'beginprice'=>$_GPC['beginprice'],
					'endprice'=>$_GPC['endprice'],
					'sort' => $_GPC['sort'],
					'enabled'=>1
					);
				if (!empty($id)) {
					pdo_update('weixinmao_zp_jobprice', $data, array('id' => $id));
				} else {
					pdo_insert('weixinmao_zp_jobprice', $data);
					$id = pdo_insertid();
				}
				message('更新薪资范围成功！', $this->createWebUrl('jobprice', array('op' => 'display')), 'success');
			}

			$oldhouseprice = pdo_fetch("select * from " . tablename('weixinmao_zp_jobprice') . " where id=:id and uniacid=:uniacid limit 1", array(":id" => $id, ":uniacid" => $_W['uniacid']));
		} elseif ($operation == 'delete') {
			$id = intval($_GPC['id']);
			$oldhouseprice = pdo_fetch("SELECT id FROM " . tablename('weixinmao_zp_jobprice') . " WHERE id = '$id' AND uniacid=" . $_W['uniacid'] . "");
			if (empty($oldhouseprice)) {
				message('抱歉，不存在或是已经被删除！', $this->createWebUrl('jobprice', array('op' => 'display')), 'error');
			}
			pdo_delete('weixinmao_zp_jobprice', array('id' => $id));
			message('删除成功！', $this->createWebUrl('jobprice', array('op' => 'display')), 'success');
		} else {
			message('请求方式不存在');
		}
		include $this->template('jobprice', TEMPLATE_INCLUDEPATH, true);
	}

	public function doWebcompanyaccount() {
		global $_W, $_GPC;
			load()->func('tpl');

		$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
			$sql = 'SELECT * FROM ' . tablename('weixinmao_zp_company') . ' WHERE `uniacid` = :uniacid ORDER BY `sort` DESC';
		
		$companylist  = pdo_fetchall($sql, array(':uniacid' => $_W['uniacid']));
		if ($operation == 'display') {
			$list = pdo_fetchall("SELECT * FROM " . tablename('weixinmao_zp_companyaccount') . " WHERE uniacid = '{$_W['uniacid']}' ");
			if($list)
			{
				foreach ($list as $k => $v) {
				
				$companyinfo = pdo_fetch("SELECT companyname FROM " . tablename('weixinmao_zp_company') . " WHERE uniacid = '{$_W['uniacid']}' AND id=".$v['companyid']);
				$list[$k]['companyname'] = $companyinfo['companyname'];
			}
			}
		} elseif ($operation == 'post') {
			$id = intval($_GPC['id']);
		
			if (checksubmit('submit')) {
				$data = array(
					'uniacid' => $_W['uniacid'],
					'name' => $_GPC['name'],
					'companyid'=>$_GPC['companyid'],
					 'createtime' => TIMESTAMP,
					'status'=>$_GPC['enabled']
					);
				if($_GPC['password'])
					$data['password'] = md5($_GPC['password']);
				if (!empty($id)) {
					pdo_update('weixinmao_zp_companyaccount', $data, array('id' => $id));
				} else {
					pdo_insert('weixinmao_zp_companyaccount', $data);
					$id = pdo_insertid();
				}
				message('更新区域成功！', $this->createWebUrl('companyaccount', array('op' => 'display')), 'success');
			}

			$companyaccount = pdo_fetch("select * from " . tablename('weixinmao_zp_companyaccount') . " where id=:id and uniacid=:uniacid limit 1", array(":id" => $id, ":uniacid" => $_W['uniacid']));
		} elseif ($operation == 'delete') {
			$id = intval($_GPC['id']);
			$oldhouseprice = pdo_fetch("SELECT id FROM " . tablename('weixinmao_zp_companyaccount') . " WHERE id = '$id' AND uniacid=" . $_W['uniacid'] . "");
			if (empty($oldhouseprice)) {
				message('抱歉，不存在或是已经被删除！', $this->createWebUrl('companyaccount', array('op' => 'display')), 'error');
			}
			pdo_delete('weixinmao_zp_companyaccount', array('id' => $id));
			message('删除成功！', $this->createWebUrl('companyaccount', array('op' => 'display')), 'success');
		} else {
			message('请求方式不存在');
		}
		include $this->template('companyaccount', TEMPLATE_INCLUDEPATH, true);
	}






		public function doWebCate() {
		//这个操作被定义用来呈现 管理中心导航菜单
		global $_GPC, $_W;
		load()->func('tpl');
		$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
		if ($operation == 'display') {
			if (!empty($_GPC['displayorder'])) {
				foreach ($_GPC['displayorder'] as $id => $displayorder) {
					pdo_update('weixinmao_zp_category', array('displayorder' => $displayorder), array('id' => $id, 'weid' => $_W['uniacid']));
				}
				message('分类排序更新成功！', $this->createWebUrl('cate', array('op' => 'display')), 'success');
			}
			$children = array();
			
			$category = pdo_fetchall("SELECT * FROM " . tablename('weixinmao_zp_category') . " WHERE weid = '{$_W['uniacid']}' ORDER BY parentid ASC, displayorder DESC");
			foreach ($category as $index => $row) {
				if (!empty($row['parentid'])) {
					$children[$row['parentid']][] = $row;
					unset($category[$index]);
				}
			}
			include $this->template('category');
		} elseif ($operation == 'post') {
			
			$parentid = intval($_GPC['parentid']);
			$id = intval($_GPC['id']);
			if (!empty($id)) {
				$category = pdo_fetch("SELECT * FROM " . tablename('weixinmao_zp_category') . " WHERE id = :id AND weid = :weid", array(':id' => $id, ':weid' => $_W['uniacid']));
			} else {
				$category = array(
					'displayorder' => 0,
				);
			}
			if (!empty($parentid)) {
				$parent = pdo_fetch("SELECT id, name FROM " . tablename('weixinmao_zp_category') . " WHERE id = '$parentid'");
				if (empty($parent)) {
					message('抱歉，上级分类不存在或是已经被删除！', $this->createWebUrl('post'), 'error');
				}
			}
			if (checksubmit('submit')) {
				if (empty($_GPC['catename'])) {
					message('抱歉，请输入分类名称！');
				}
				$data = array(
					'weid' => $_W['uniacid'],
					'name' => $_GPC['catename'],
					'enabled' => intval($_GPC['enabled']),
					'displayorder' => intval($_GPC['displayorder']),
					'isrecommand' => intval($_GPC['isrecommand']),
					'model'=>intval($_GPC['model']),
					'description' => $_GPC['description'],
					'parentid' => intval($parentid),
					'thumb' => $_GPC['thumb']
				);
				if (!empty($id)) {
					unset($data['parentid']);
					pdo_update('weixinmao_zp_category', $data, array('id' => $id, 'weid' => $_W['uniacid']));
					load()->func('file');
					file_delete($_GPC['thumb_old']);
				} else {
					pdo_insert('weixinmao_zp_category', $data);
					$id = pdo_insertid();
				}
				message('更新分类成功！', $this->createWebUrl('cate', array('op' => 'display')), 'success');
			}
			include $this->template('category');
		} elseif ($operation == 'delete') {
			$id = intval($_GPC['id']);
			$category = pdo_fetch("SELECT id, parentid FROM " . tablename('weixinmao_zp_category') . " WHERE id = '$id'");
			if (empty($category)) {
				message('抱歉，分类不存在或是已经被删除！', $this->createWebUrl('weixinmao_zp_category', array('op' => 'display')), 'error');
			}
			pdo_delete('weixinmao_zp_category', array('id' => $id, 'parentid' => $id), 'OR');
			message('分类删除成功！', $this->createWebUrl('cate', array('op' => 'display')), 'success');
		}
		
	}




public function doWebActive() {
		//这个操作被定义用来呈现 管理中心导航菜单
		global $_GPC, $_W;
		load()->func('tpl');

	
		$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
		if ($operation == 'post') {
			
			$id = $_GPC['id'];
	
			 if (!empty($id)) {
				 $item = pdo_fetch("SELECT *  FROM " . tablename('weixinmao_zp_active') . " WHERE id = :id", array(':id' => $id));		
			}
		  //  $newhouselist = pdo_fetchall("SELECT id,housename  FROM " . tablename('weixinmao_house_houseinfo') . " WHERE uniacid = :uniacid", array(':uniacid' => $_W['uniacid']));		
			
			if (checksubmit('submit')) {
				if(is_array($_GPC['thumbs'])){
					$thumb_data['thumb_url'] = serialize($_GPC['thumbs']);
				}
                $data = array(
                    'uniacid' => $_W['uniacid'],
					'title'=>$_GPC['title'],
					'begintime'=>$_GPC['begintime'],
					'mainwork'=>$_GPC['mainwork'],
					'fuwork'=>$_GPC['fuwork'],
                    'content' => ihtmlspecialchars($_GPC['content']),
					'sort'=>$_GPC['sort'],
					'thumb'=>$_GPC['thumb'],
                    'createtime' => TIMESTAMP,
					'money'=>$_GPC['money'],
					'pid'=>$_GPC['pid']
                );
               
                if (!empty($id)) {
                    unset($data['createtime']);
                    pdo_update('weixinmao_zp_active', $data, array('id' => $id));
                } else {
                    pdo_insert('weixinmao_zp_active', $data);
                    $id = pdo_insertid();
                }
                message('更新成功！', $this->createWebUrl('active', array('op' => 'display')), 'success');
            }
			
			
			
			
		} elseif ($operation == 'display') {
			
		
			$pindex = max(1, intval($_GPC['page']));
			$psize = 15;
			$condition = ' WHERE `uniacid` = :uniacid ';
			$params = array(':uniacid' => $_W['uniacid']);
			
			if (!empty($_GPC['keyword'])) {
				$condition .= ' AND `title` LIKE :title';
				$params[':title'] = '%' . trim($_GPC['keyword']) . '%';
			}
			
			
			$sql = 'SELECT COUNT(*) FROM ' . tablename('weixinmao_zp_active') .$condition ;

			$total = pdo_fetchcolumn($sql, $params);
			
			if (!empty($total)) {
				$sql = 'SELECT * FROM  ' . tablename('weixinmao_zp_active') .$condition.' ORDER BY  `sort`  DESC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
				$list = pdo_fetchall($sql, $params);
				$pager = pagination($total, $pindex, $psize);
			}
			
			
			
		}elseif ($operation == 'delete') {
			$id = intval($_GPC['id']);
			$row = pdo_fetch("SELECT id FROM " . tablename('weixinmao_zp_active') . " WHERE id = :id", array(':id' => $id));
			if (empty($row)) {
				message('抱歉，商品不存在或是已经被删除！');
			}
			pdo_delete('weixinmao_zp_active', array('id' => $id));

			message('删除成功！', referer(), 'success');
		}
		include $this->template('active');
		
	}



public function doWebToplist() {
		global $_W, $_GPC;
	    load()->func('tpl');
		$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
		if ($operation == 'display') {
			$list = pdo_fetchall("SELECT * FROM " . tablename('weixinmao_zp_toplist') . " WHERE uniacid = '{$_W['uniacid']}' ORDER BY sort DESC");
		} elseif ($operation == 'post') {
			$id = intval($_GPC['id']);
				
			if (checksubmit('submit')) {
				$data = array(
					'uniacid' => $_W['uniacid'],
					'title' => $_GPC['title'],
					'money' => $_GPC['money'],
				    'days'=>$_GPC['days'],
					'sort' => $_GPC['sort'],
					'enabled'=>1
					);
				if (!empty($id)) {
					pdo_update('weixinmao_zp_toplist', $data, array('id' => $id));
				} else {
					pdo_insert('weixinmao_zp_toplist', $data);
					$id = pdo_insertid();
				}
				message('更新成功！', $this->createWebUrl('toplist', array('op' => 'display')), 'success');
			}

			$toplist = pdo_fetch("select * from " . tablename('weixinmao_zp_toplist') . " where id=:id and uniacid=:uniacid limit 1", array(":id" => $id, ":uniacid" => $_W['uniacid']));
			
		} elseif ($operation == 'delete') {
			$id = intval($_GPC['id']);
			$oldhouseprice = pdo_fetch("SELECT id FROM " . tablename('weixinmao_zp_toplist') . " WHERE id = '$id' AND uniacid=" . $_W['uniacid'] . "");
			if (empty($oldhouseprice)) {
				message('抱歉，不存在或是已经被删除！', $this->createWebUrl('toplist', array('op' => 'display')), 'error');
			}
			pdo_delete('weixinmao_zp_toplist', array('id' => $id));
			message('删除成功！', $this->createWebUrl('toplist', array('op' => 'display')), 'success');
		} else {
			message('请求方式不存在');
		}
		include $this->template('toplist', TEMPLATE_INCLUDEPATH, true);
	}



public function doWebPaytoplist() {
		global $_W, $_GPC;
	    load()->func('tpl');
		$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
		if ($operation == 'display') {
			$list = pdo_fetchall("SELECT * FROM " . tablename('weixinmao_zp_paytoplist') . " WHERE uniacid = '{$_W['uniacid']}' ORDER BY sort DESC");
		} elseif ($operation == 'post') {
			$id = intval($_GPC['id']);
				
			if (checksubmit('submit')) {
				$data = array(
					'uniacid' => $_W['uniacid'],
					'title' => $_GPC['title'],
					'money' => $_GPC['money'],
				    'days'=>$_GPC['days'],
					'sort' => $_GPC['sort'],
					'enabled'=>1
					);
				if (!empty($id)) {
					pdo_update('weixinmao_zp_paytoplist', $data, array('id' => $id));
				} else {
					pdo_insert('weixinmao_zp_paytoplist', $data);
					$id = pdo_insertid();
				}
				message('更新成功！', $this->createWebUrl('paytoplist', array('op' => 'display')), 'success');
			}

			$toplist = pdo_fetch("select * from " . tablename('weixinmao_zp_paytoplist') . " where id=:id and uniacid=:uniacid limit 1", array(":id" => $id, ":uniacid" => $_W['uniacid']));
			
		} elseif ($operation == 'delete') {
			$id = intval($_GPC['id']);
			$oldhouseprice = pdo_fetch("SELECT id FROM " . tablename('weixinmao_zp_paytoplist') . " WHERE id = '$id' AND uniacid=" . $_W['uniacid'] . "");
			if (empty($oldhouseprice)) {
				message('抱歉，不存在或是已经被删除！', $this->createWebUrl('paytoplist', array('op' => 'display')), 'error');
			}
			pdo_delete('weixinmao_zp_paytoplist', array('id' => $id));
			message('删除成功！', $this->createWebUrl('paytoplist', array('op' => 'display')), 'success');
		} else {
			message('请求方式不存在');
		}
		include $this->template('paytoplist', TEMPLATE_INCLUDEPATH, true);
	}


public function doWebPayjoblist() {
		global $_W, $_GPC;
	    load()->func('tpl');
		$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
		if ($operation == 'display') {
			$list = pdo_fetchall("SELECT * FROM " . tablename('weixinmao_zp_payjoblist') . " WHERE uniacid = '{$_W['uniacid']}' ORDER BY sort DESC");
		} elseif ($operation == 'post') {
			$id = intval($_GPC['id']);
				
			if (checksubmit('submit')) {
				$data = array(
					'uniacid' => $_W['uniacid'],
					'title' => $_GPC['title'],
					'money' => $_GPC['money'],
				    'days'=>$_GPC['days'],
					'sort' => $_GPC['sort'],
					'enabled'=>1
					);
				if (!empty($id)) {
					pdo_update('weixinmao_zp_payjoblist', $data, array('id' => $id));
				} else {
					pdo_insert('weixinmao_zp_payjoblist', $data);
					$id = pdo_insertid();
				}
				message('更新区域成功！', $this->createWebUrl('payjoblist', array('op' => 'display')), 'success');
			}

			$toplist = pdo_fetch("select * from " . tablename('weixinmao_zp_payjoblist') . " where id=:id and uniacid=:uniacid limit 1", array(":id" => $id, ":uniacid" => $_W['uniacid']));
			
		} elseif ($operation == 'delete') {
			$id = intval($_GPC['id']);
			$oldhouseprice = pdo_fetch("SELECT id FROM " . tablename('weixinmao_zp_payjoblist') . " WHERE id = '$id' AND uniacid=" . $_W['uniacid'] . "");
			if (empty($oldhouseprice)) {
				message('抱歉，不存在或是已经被删除！', $this->createWebUrl('payjoblist', array('op' => 'display')), 'error');
			}
			pdo_delete('weixinmao_zp_payjoblist', array('id' => $id));
			message('删除成功！', $this->createWebUrl('payjoblist', array('op' => 'display')), 'success');
		} else {
			message('请求方式不存在');
		}
		include $this->template('payjoblist', TEMPLATE_INCLUDEPATH, true);
	}



public function doWebCompanyrole() {
		global $_W, $_GPC;
	    load()->func('tpl');
		$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
		if ($operation == 'display') {
			$list = pdo_fetchall("SELECT * FROM " . tablename('weixinmao_zp_companyrole') . " WHERE uniacid = '{$_W['uniacid']}' ORDER BY sort DESC");
		} elseif ($operation == 'post') {
			$id = intval($_GPC['id']);
				
			if (checksubmit('submit')) {
				$data = array(
					'uniacid' => $_W['uniacid'],
					'title' => $_GPC['title'],
					'money' => $_GPC['money'],
				    'days'=>$_GPC['days'],
					'jobnum'=>$_GPC['jobnum'],
					'notenum'=>$_GPC['notenum'],
					'isinit'=>$_GPC['isinit'],
					'sort' => $_GPC['sort'],
					'enabled'=>1
					);
				if (!empty($id)) {
					pdo_update('weixinmao_zp_companyrole', $data, array('id' => $id));
				} else {
					pdo_insert('weixinmao_zp_companyrole', $data);
					$id = pdo_insertid();
				}
				message('更新区域成功！', $this->createWebUrl('companyrole', array('op' => 'display')), 'success');
			}

			$toplist = pdo_fetch("select * from " . tablename('weixinmao_zp_companyrole') . " where id=:id and uniacid=:uniacid limit 1", array(":id" => $id, ":uniacid" => $_W['uniacid']));
			
		}elseif($operation == 'updaterole'){

			$roleid = $_GPC['roleid'];
			if($roleid == 0 )
			{
			message('请选择同步等级');
			}

		   $companyrole = pdo_get('weixinmao_zp_companyrole',array('uniacid'=>$_W['uniacid'],'id'=>$roleid));
		   $endtime = time()+60*60*24*$companyrole['days'];
		   $data = array('endtime'=>$endtime);
          	$companydata = array('jobnum'=>$companyrole['jobnum'],'notenum'=>$companyrole['notenum'],'endtime'=>$endtime,'roleid'=>$roleid);

		   
		   pdo_update('weixinmao_zp_company',$companydata,array('uniacid'=>$_W['uniacid']));
		   pdo_update('weixinmao_zp_job',$data,array('uniacid'=>$_W['uniacid']));

			message('同步成功！', $this->createWebUrl('companyrole', array('op' => 'display')), 'success');


		}elseif ($operation == 'delete') {
			$id = intval($_GPC['id']);
			$oldhouseprice = pdo_fetch("SELECT id FROM " . tablename('weixinmao_zp_companyrole') . " WHERE id = '$id' AND uniacid=" . $_W['uniacid'] . "");
			if (empty($oldhouseprice)) {
				message('抱歉，不存在或是已经被删除！', $this->createWebUrl('companyrole', array('op' => 'display')), 'error');
			}
			pdo_delete('weixinmao_zp_companyrole', array('id' => $id));
			message('删除成功！', $this->createWebUrl('companyrole', array('op' => 'display')), 'success');
		} else {
			message('请求方式不存在');
		}
		include $this->template('companyrole', TEMPLATE_INCLUDEPATH, true);
	}



  public function doWebOrder()
	{
		global $_GPC, $_W;
		load()->func('tpl');
		$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
		
		if ($operation == 'post') {
			$id = $_GPC['id'];
			if (!empty($id)) {
				 $item = pdo_fetch("SELECT *  FROM " . tablename('weixinmao_zp_order') . " WHERE id = :id", array(':id' => $id));			
			}
			if (checksubmit('submit')) {
				//print_r($_GPC);
				//exit;
                $data = array(
                    'uniacid' => $_W['uniacid'],
					'title'=>$_GPC['title'],
                    'content' => htmlspecialchars_decode($_GPC['content']),
					'sort'=>$_GPC['sort'],
					'thumb'=>$_GPC['thumb'],
                    'createtime' => TIMESTAMP,
                );
                if (!empty($id)) {
                    unset($data['createtime']);
                    pdo_update('weixinmao_zp_order', $data, array('id' => $id));
                } else {
                    pdo_insert('weixinmao_zp_order', $data);
                    $id = pdo_insertid();
                }
                message('更新成功！', $this->createWebUrl('order', array('op' => 'display')), 'success');
            }
		} elseif($operation == 'done'){
			
			$id = intval($_GPC['id']);
			$row = pdo_fetch("SELECT id FROM " . tablename('weixinmao_zp_order') . " WHERE id = :id", array(':id' => $id));
			if (empty($row)) {
				message('抱歉，订单不存在或是已经被删除！');
			}
			 pdo_update('weixinmao_zp_order', array('status'=>2), array('id' => $id));

			message('操作成功！', referer(), 'success');
			
		
		}elseif ($operation == 'display') {
			$status = $_GPC['status'];
			if(!isset($status))
					$status = -1;
			$pindex = max(1, intval($_GPC['page']));
			$psize = 15;
			$condition = ' WHERE `uniacid` = :uniacid ';
			$params = array(':uniacid' => $_W['uniacid']);
			
			if (!empty($_GPC['member'])) {
				$condition .= ' AND `tel` LIKE :title';
				$params[':title'] = '%' . trim($_GPC['member']) . '%';
			}
			if($status ==0)
			{
				$condition .= ' AND `paid` = 0 ';
			}elseif($status ==1)
			{
					$condition .= ' AND `paid` = 1 AND status =1 ';
			}elseif($status == 2){
				
				$condition .= ' AND `paid` = 1 AND status =2 ';
			}elseif($status ==3){
				
				$condition .= ' AND `paid` = 1 AND status =3 ';
			}
			
			$sql = 'SELECT COUNT(*) FROM ' . tablename('weixinmao_zp_order') .$condition ;

			$total = pdo_fetchcolumn($sql, $params);
			
			if (!empty($total)) {
				$sql = 'SELECT * FROM  ' . tablename('weixinmao_zp_order') .$condition.' ORDER BY  `createtime`  DESC LIMIT ' . ($pindex - 1) * $psize . ',' . $psize;
				$list = pdo_fetchall($sql, $params);
				$pager = pagination($total, $pindex, $psize);
				if($list)
				{
						foreach($list as $k=>$v)
						{
							if($v['couponid']>0)
							{
								$coupon_order = pdo_fetch("SELECT title FROM " . tablename('weixinmao_house_order') . " WHERE id = :id", array(':id' => $v['couponid']));
								//print_r($coupon_order);
								$list[$k]['coupon'] = $coupon_order['title'];
							}else{
								
								$list[$k]['coupon'] = '';
							}
						}
					
				}
				
			}
			
		} elseif ($operation == 'delete') {
			$id = intval($_GPC['id']);
			$row = pdo_fetch("SELECT id FROM " . tablename('weixinmao_zp_order') . " WHERE id = :id", array(':id' => $id));
			if (empty($row)) {
				message('抱歉，订单不存在或是已经被删除！');
			}
			pdo_delete('weixinmao_zp_order', array('id' => $id));
			message('删除成功！', referer(), 'success');
		}
		include $this->template('order');
		
	}













  }